import { getImageByUrl } from '@/utils/getImageByUrl'
import { Space, Typography, Popconfirm, Image } from 'antd'
import type { ColumnsType } from 'antd/es/table'
import type { TableData } from './types'
type fun = (...set: any) => void
interface Props {
  onView: fun
  onEdit: fun
  onRecovery: fun
  onOpen: fun
  onDel: fun
}
export const userColumns = (props: Props): ColumnsType<TableData> => [
  {
    title: '编号',
    align: 'center',
    dataIndex: 'numbering',
  },
  {
    title: '名称',
    align: 'center',
    dataIndex: 'name',
    key: 'name',
  },
  {
    title: '型号',
    align: 'center',
    dataIndex: 'model',
    key: 'model',
  },
  {
    title: '厂商',
    align: 'center',
    dataIndex: 'manufacturer',
    key: 'manufacturer',
  },
  {
    title: '数量',
    align: 'center',
    dataIndex: 'total_num',
    key: 'total_num',
  },
  {
    title: '类型',
    align: 'center',
    dataIndex: 'type',
    key: 'type',
    render: (type) => (type === 1 ? '用户设备' : '空间设备'),
  },
  {
    title: '操作',
    align: 'center',
    fixed: 'right',
    width: 350,
    render: (data: TableData) => (
      <Space size={'large'}>
        <Typography.Link
          onClick={() => {
            props?.onView(data?.id, data?.type)
          }}
        >
          查看
          {/* {type === '1' ? '用户' : '空间'} */}
        </Typography.Link>
        <Typography.Link
          onClick={() => {
            props?.onEdit(data?.id, data?.type)
          }}
        >
          编辑
        </Typography.Link>
        <Popconfirm
          title={`确认要回收吗？`}
          onConfirm={() => props?.onRecovery(data?.id)}
          okText="确认"
          cancelText="取消"
        >
          <Typography.Link>回收</Typography.Link>
        </Popconfirm>

        <Typography.Link onClick={() => props?.onOpen(data?.id)}>启用</Typography.Link>

        <Popconfirm title={`确认删除吗？`} onConfirm={() => props?.onDel(data?.id)} okText="确认" cancelText="取消">
          <Typography.Link>删除</Typography.Link>
        </Popconfirm>
      </Space>
    ),
  },
]

export const eventColumns = (props: Record<string, fun>): ColumnsType<TableData> => [
  {
    title: '编号',
    align: 'center',
    dataIndex: 'numbering',
  },
  {
    title: '名称',
    align: 'center',
    dataIndex: 'name',
    key: 'name',
  },
  {
    title: '型号',
    align: 'center',
    dataIndex: 'age',
    key: 'age',
  },
  {
    title: '厂商',
    align: 'center',
    dataIndex: 'name',
    key: 'name',
  },
  {
    title: '数量',
    align: 'center',
    dataIndex: 'phone',
    key: 'phone',
  },
  {
    title: '类型',
    align: 'center',
    dataIndex: 'type',
    key: 'type',
    render: (type) => (type === 1 ? '用户设备' : '空间设备'),
  },
]
export const offlineColumns = (props: Record<string, fun>): ColumnsType<TableData> => [
  {
    title: '编号',
    align: 'center',
    dataIndex: 'numbering',
  },
  {
    title: '名称',
    align: 'center',
    dataIndex: 'name',
    key: 'name',
  },
]
